package cn.raven.order.controller;

import cn.raven.basic.annotation.PreAuthorize;
import cn.raven.basic.exception.BusinessException;
import cn.raven.order.dto.OrderConfirmationDto;
import cn.raven.order.dto.OrderDto;
import cn.raven.order.service.IOrderPetAcquisitionService;
import cn.raven.order.domain.OrderPetAcquisition;
import cn.raven.order.query.OrderPetAcquisitionQuery;
import cn.raven.basic.utils.AjaxResult;
import cn.raven.basic.utils.PageList;
import cn.raven.pet.dto.HandlerMsgDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orderPetAcquisition")
public class OrderPetAcquisitionController {
    @Autowired
    public IOrderPetAcquisitionService orderPetAcquisitionService;


    /**
     * 保存和修改公用的
     * @param orderPetAcquisition  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult save(@RequestBody OrderPetAcquisition orderPetAcquisition){
        try {
            if( orderPetAcquisition.getId()!=null)
                orderPetAcquisitionService.update(orderPetAcquisition);
            else
                orderPetAcquisitionService.add(orderPetAcquisition);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("保存对象失败！"+e.getMessage());
        }
    }
    /**
    * 取消订单
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult del(@PathVariable("id") Long id){
        try {
            orderPetAcquisitionService.cancel(id);
            return AjaxResult.me();
        } catch (Exception e) {
        e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("删除对象失败！"+e.getMessage());
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
    public OrderPetAcquisition findById(@PathVariable("id")Long id)
    {
        return orderPetAcquisitionService.findOne(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    public List<OrderPetAcquisition> findAll(){

        return orderPetAcquisitionService.findAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/list")
    public PageList<OrderPetAcquisition> queryData(@RequestBody OrderPetAcquisitionQuery query)
    {
        return orderPetAcquisitionService.queryData(query);
    }
    
    /** 
    * @Title: confirm
    * @Description: 确认订单
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/7/20 19:09  
    * @Parameters: [orderPetAcquisition]
    * @Return cn.raven.basic.utils.AjaxResult
      */    @PostMapping("/confirm")
    public AjaxResult confirm(@RequestBody OrderConfirmationDto dto){
        try {
            orderPetAcquisitionService.confirm(dto);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage()).setSuccess(false);
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统繁忙,请骚后重试").setSuccess(false);
        }
    }



}
